***************************************************************************
************** Table 4: Heterogeneity in Policy Effect ********************
***************************************************************************


cd $PATH

use analysis_main.dta, clear

xtset commid WAVE
global score comm denc div econ health house market soc trans edc mart sani

eststo clear

* 1) urban-rural gap

g urban=T2==1

local dependent loggini logtheil logpctratio_p90p10 logpctratio_p75p25
foreach y of local dependent{
eststo: qui xtreg `y' tcz##post##urban $score i.WAVE i.T1, fe vce(cluster commid)
}


* 2) regulatory stringency

local dependent loggini logtheil logpctratio_p90p10 logpctratio_p75p25
foreach y of local dependent{
eststo: qui xtreg `y' tcz##post##corecity $score i.WAVE i.T1, fe vce(cluster commid)
}

* 3) emissions differentials

* High SO2-emitting provinces: T1 37- SHANDONG 52-GUIZHOU 32-JIANGSU
g highemi=T1==37|T1==52|T1==32
label var highemi "high SO2-emitting provinces"

local dependent loggini logtheil logpctratio_p90p10 logpctratio_p75p25
foreach y of local dependent{
eststo: qui xtreg `y' tcz##post##highemi $score i.WAVE i.T1, fe vce(cluster commid)
}

* 4) generate Table 4

esttab est1 est2 est3 est4 using hetero.tex, b(a2) se(a2) keep(1.tcz#1.post#1.urban 1.tcz#1.post) starlevels(* 0.10 ** 0.05 *** 0.01)  ///
stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. \(R^{2}\)")) mtitles("Gini" "Theil" "P90/P10" "P75/P25")  ///
prehead("\begin{tabular}{l*{4}{c}} \hline\hline") posthead("\hline \multicolumn{5}{l}{\textbf{A: Urban-rural gap}} \\ ") ///
label nolines replace fragment

esttab est5 est6 est7 est8 using hetero.tex, b(a2) se(a2)  keep(1.tcz#1.post#1.corecity 1.tcz#1.post) starlevels(* 0.10 ** 0.05 *** 0.01)  ///
stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. \(R^{2}\)")) posthead("\hline \multicolumn{5}{l}{\textbf{B: Regulatory stringency}} \\") ///
label fragment append nomtitles nonumbers nolines 

esttab est9 est10 est11 est12 using hetero.tex, b(a2) se(a2) keep(1.tcz#1.post#1.highemi 1.tcz#1.post) starlevels(* 0.10 ** 0.05 *** 0.01)  ///
stats(N r2_a, fmt(%9.0fc %9.3f) labels("Observations" "Adj. \(R^{2}\)")) posthead("\hline \multicolumn{5}{l}{\textbf{C: Emission differentials}} \\") postfoot("\hline \end{tabular}") ///
label fragment append nomtitles nonumbers nolines


